import React, { Component, createContext, useContext } from "react";

export default function FunComRouter() {
  return (
    <>
      <div>
        <NavContext.Provider value={history}>
          <ChildRouter></ChildRouter>
        </NavContext.Provider>
      </div>
    </>
  );
}
const NavContext = createContext(null);


const history = window.history;
const withRouter = (Component) => {
  return function WithRouterComponent() {
    const history = useContext(NavContext);
    console.log(history);
    

    
    return <Component history={history}></Component>;
  };
};
const Child = ({ history }) => {
  return (
    <>
      <div>
        <button onClick={() => history.pushState({}, null, "/hello")}>
          to hello
        </button>
      </div>
    </>
  );
};
const ChildRouter = withRouter(Child);
